<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>27.6. timeit — Measure execution time of small code snippets &mdash; Python v2.6.2 documentation</title>
    <link rel="stylesheet" href="../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '2.6.2',
        COLLAPSE_MODINDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <link rel="search" type="application/opensearchdescription+xml"
          title="Search within Python v2.6.2 documentation"
          href="../_static/opensearch.xml"/>
    <link rel="author" title="About these documents" href="../about.html" />
    <link rel="copyright" title="Copyright" href="../copyright.html" />
    <link rel="top" title="Python v2.6.2 documentation" href="../index.html" />
    <link rel="up" title="27. Debugging and Profiling" href="debug.html" />
    <link rel="next" title="27.7. trace — Trace or track Python statement execution" href="trace.html" />
    <link rel="prev" title="27.5. hotshot — High performance logging profiler" href="hotshot.html" />
    <link rel="shortcut icon" type="image/png" href="../_static/py.png" />
 

  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../modindex.html" title="Global Module Index"
             accesskey="M">modules</a> |</li>
        <li class="right" >
          <a href="trace.html" title="27.7. trace — Trace or track Python statement execution"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="hotshot.html" title="27.5. hotshot — High performance logging profiler"
             accesskey="P">previous</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="../index.html">Python v2.6.2 documentation</a> &raquo;</li>

          <li><a href="index.html" >The Python Standard Library</a> &raquo;</li>
          <li><a href="debug.html" accesskey="U">27. Debugging and Profiling</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="module-timeit">
<h1>27.6. <tt class="xref docutils literal"><span class="pre">timeit</span></tt> &#8212; Measure execution time of small code snippets<a class="headerlink" href="#module-timeit" title="Permalink to this headline">¶</a></h1>
<p>
<span class="versionmodified">New in version 2.3.</span></p>
<p id="index-665">This module provides a simple way to time small bits of Python code. It has both
command line as well as callable interfaces.  It avoids a number of common traps
for measuring execution times.  See also Tim Peters&#8217; introduction to the
&#8220;Algorithms&#8221; chapter in the Python Cookbook, published by O&#8217;Reilly.</p>
<p>The module defines the following public class:</p>
<dl class="class">
<dt id="timeit.Timer">
<em class="property">
class </em><tt class="descclassname">timeit.</tt><tt class="descname">Timer</tt><big>(</big><span class="optional">[</span><em>stmt='pass'</em><span class="optional">[</span>, <em>setup='pass'</em><span class="optional">[</span>, <em>timer=&lt;timer function&gt;</em><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><big>)</big><a class="headerlink" href="#timeit.Timer" title="Permalink to this definition">¶</a></dt>
<dd><p>Class for timing execution speed of small code snippets.</p>
<p>The constructor takes a statement to be timed, an additional statement used for
setup, and a timer function.  Both statements default to <tt class="docutils literal"><span class="pre">'pass'</span></tt>; the timer
function is platform-dependent (see the module doc string).  The statements may
contain newlines, as long as they don&#8217;t contain multi-line string literals.</p>
<p>To measure the execution time of the first statement, use the <a title="timeit.timeit" class="reference internal" href="#timeit.timeit"><tt class="xref docutils literal"><span class="pre">timeit()</span></tt></a>
method.  The <a title="timeit.repeat" class="reference internal" href="#timeit.repeat"><tt class="xref docutils literal"><span class="pre">repeat()</span></tt></a> method is a convenience to call <a title="timeit.timeit" class="reference internal" href="#timeit.timeit"><tt class="xref docutils literal"><span class="pre">timeit()</span></tt></a>
multiple times and return a list of results.</p>
<p>
<span class="versionmodified">Changed in version 2.6: </span>The <em>stmt</em> and <em>setup</em> parameters can now also take objects that are callable
without arguments. This will embed calls to them in a timer function that will
then be executed by <a title="timeit.timeit" class="reference internal" href="#timeit.timeit"><tt class="xref docutils literal"><span class="pre">timeit()</span></tt></a>.  Note that the timing overhead is a little
larger in this case because of the extra function calls.</p>
</dd></dl>

<dl class="method">
<dt id="timeit.Timer.print_exc">
<tt class="descclassname">Timer.</tt><tt class="descname">print_exc</tt><big>(</big><span class="optional">[</span><em>file=None</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#timeit.Timer.print_exc" title="Permalink to this definition">¶</a></dt>
<dd><p>Helper to print a traceback from the timed code.</p>
<p>Typical use:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">t</span> <span class="o">=</span> <span class="n">Timer</span><span class="p">(</span><span class="o">...</span><span class="p">)</span>       <span class="c"># outside the try/except</span>
<span class="k">try</span><span class="p">:</span>
    <span class="n">t</span><span class="o">.</span><span class="n">timeit</span><span class="p">(</span><span class="o">...</span><span class="p">)</span>    <span class="c"># or t.repeat(...)</span>
<span class="k">except</span><span class="p">:</span>
    <span class="n">t</span><span class="o">.</span><span class="n">print_exc</span><span class="p">()</span>
</pre></div>
</div>
<p>The advantage over the standard traceback is that source lines in the compiled
template will be displayed. The optional <em>file</em> argument directs where the
traceback is sent; it defaults to <tt class="docutils literal"><span class="pre">sys.stderr</span></tt>.</p>
</dd></dl>

<dl class="method">
<dt id="timeit.Timer.repeat">
<tt class="descclassname">Timer.</tt><tt class="descname">repeat</tt><big>(</big><span class="optional">[</span><em>repeat=3</em><span class="optional">[</span>, <em>number=1000000</em><span class="optional">]</span><span class="optional">]</span><big>)</big><a class="headerlink" href="#timeit.Timer.repeat" title="Permalink to this definition">¶</a></dt>
<dd><p>Call <a title="timeit.timeit" class="reference internal" href="#timeit.timeit"><tt class="xref docutils literal"><span class="pre">timeit()</span></tt></a> a few times.</p>
<p>This is a convenience function that calls the <a title="timeit.timeit" class="reference internal" href="#timeit.timeit"><tt class="xref docutils literal"><span class="pre">timeit()</span></tt></a> repeatedly,
returning a list of results.  The first argument specifies how many times to
call <a title="timeit.timeit" class="reference internal" href="#timeit.timeit"><tt class="xref docutils literal"><span class="pre">timeit()</span></tt></a>.  The second argument specifies the <em>number</em> argument for
<a title="timeit.timeit" class="reference internal" href="#timeit.timeit"><tt class="xref docutils literal"><span class="pre">timeit()</span></tt></a>.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">It&#8217;s tempting to calculate mean and standard deviation from the result vector
and report these.  However, this is not very useful.  In a typical case, the
lowest value gives a lower bound for how fast your machine can run the given
code snippet; higher values in the result vector are typically not caused by
variability in Python&#8217;s speed, but by other processes interfering with your
timing accuracy.  So the <a title="min" class="reference external" href="functions.html#min"><tt class="xref docutils literal"><span class="pre">min()</span></tt></a> of the result is probably the only number
you should be interested in.  After that, you should look at the entire vector
and apply common sense rather than statistics.</p>
</div>
</dd></dl>

<dl class="method">
<dt id="timeit.Timer.timeit">
<tt class="descclassname">Timer.</tt><tt class="descname">timeit</tt><big>(</big><span class="optional">[</span><em>number=1000000</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#timeit.Timer.timeit" title="Permalink to this definition">¶</a></dt>
<dd><p>Time <em>number</em> executions of the main statement. This executes the setup
statement once, and then returns the time it takes to execute the main statement
a number of times, measured in seconds as a float.  The argument is the number
of times through the loop, defaulting to one million.  The main statement, the
setup statement and the timer function to be used are passed to the constructor.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p>By default, <a title="timeit.timeit" class="reference internal" href="#timeit.timeit"><tt class="xref docutils literal"><span class="pre">timeit()</span></tt></a> temporarily turns off <a class="reference external" href="../glossary.html#term-garbage-collection"><em class="xref">garbage collection</em></a>
during the timing.  The advantage of this approach is that it makes
independent timings more comparable.  This disadvantage is that GC may be
an important component of the performance of the function being measured.
If so, GC can be re-enabled as the first statement in the <em>setup</em> string.
For example:</p>
<div class="last highlight-python"><div class="highlight"><pre><span class="n">timeit</span><span class="o">.</span><span class="n">Timer</span><span class="p">(</span><span class="s">&#39;for i in xrange(10): oct(i)&#39;</span><span class="p">,</span> <span class="s">&#39;gc.enable()&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">timeit</span><span class="p">()</span>
</pre></div>
</div>
</div>
</dd></dl>

<p>Starting with version 2.6, the module also defines two convenience functions:</p>
<dl class="function">
<dt id="timeit.repeat">
<tt class="descclassname">timeit.</tt><tt class="descname">repeat</tt><big>(</big><em>stmt</em><span class="optional">[</span>, <em>setup</em><span class="optional">[</span>, <em>timer</em><span class="optional">[</span>, <em>repeat=3</em><span class="optional">[</span>, <em>number=1000000</em><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><big>)</big><a class="headerlink" href="#timeit.repeat" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a <a title="timeit.Timer" class="reference internal" href="#timeit.Timer"><tt class="xref docutils literal"><span class="pre">Timer</span></tt></a> instance with the given statement, setup code and timer
function and run its <a title="timeit.repeat" class="reference internal" href="#timeit.repeat"><tt class="xref docutils literal"><span class="pre">repeat()</span></tt></a> method with the given repeat count and
<em>number</em> executions.</p>
<p>
<span class="versionmodified">New in version 2.6.</span></p>
</dd></dl>

<dl class="function">
<dt id="timeit.timeit">
<tt class="descclassname">timeit.</tt><tt class="descname">timeit</tt><big>(</big><em>stmt</em><span class="optional">[</span>, <em>setup</em><span class="optional">[</span>, <em>timer</em><span class="optional">[</span>, <em>number=1000000</em><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><big>)</big><a class="headerlink" href="#timeit.timeit" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a <a title="timeit.Timer" class="reference internal" href="#timeit.Timer"><tt class="xref docutils literal"><span class="pre">Timer</span></tt></a> instance with the given statement, setup code and timer
function and run its <a title="timeit.timeit" class="reference internal" href="#timeit.timeit"><tt class="xref docutils literal"><span class="pre">timeit()</span></tt></a> method with <em>number</em> executions.</p>
<p>
<span class="versionmodified">New in version 2.6.</span></p>
</dd></dl>

<div class="section" id="command-line-interface">
<h2>27.6.1. Command Line Interface<a class="headerlink" href="#command-line-interface" title="Permalink to this headline">¶</a></h2>
<p>When called as a program from the command line, the following form is used:</p>
<div class="highlight-python"><pre>python -m timeit [-n N] [-r N] [-s S] [-t] [-c] [-h] [statement ...]</pre>
</div>
<p>where the following options are understood:</p>
<dl class="docutils">
<dt>-n N/<em class="xref">--number=N</em></dt>
<dd>how many times to execute &#8216;statement&#8217;</dd>
<dt>-r N/<em class="xref">--repeat=N</em></dt>
<dd>how many times to repeat the timer (default 3)</dd>
<dt>-s S/<em class="xref">--setup=S</em></dt>
<dd>statement to be executed once initially (default <tt class="docutils literal"><span class="pre">'pass'</span></tt>)</dd>
<dt>-t/<em class="xref">--time</em></dt>
<dd>use <a title="time.time" class="reference external" href="time.html#time.time"><tt class="xref docutils literal"><span class="pre">time.time()</span></tt></a> (default on all platforms but Windows)</dd>
<dt>-c/<em class="xref">--clock</em></dt>
<dd>use <a title="time.clock" class="reference external" href="time.html#time.clock"><tt class="xref docutils literal"><span class="pre">time.clock()</span></tt></a> (default on Windows)</dd>
<dt>-v/<em class="xref">--verbose</em></dt>
<dd>print raw timing results; repeat for more digits precision</dd>
<dt>-h/<a class="reference external" href="../using/cmdline.html#cmdoption--help"><em class="xref">--help</em></a></dt>
<dd>print a short usage message and exit</dd>
</dl>
<p>A multi-line statement may be given by specifying each line as a separate
statement argument; indented lines are possible by enclosing an argument in
quotes and using leading spaces.  Multiple <a class="reference external" href="../using/cmdline.html#cmdoption-s"><em class="xref">-s</em></a> options are treated
similarly.</p>
<p>If <em class="xref">-n</em> is not given, a suitable number of loops is calculated by trying
successive powers of 10 until the total time is at least 0.2 seconds.</p>
<p>The default timer function is platform dependent.  On Windows,
<a title="time.clock" class="reference external" href="time.html#time.clock"><tt class="xref docutils literal"><span class="pre">time.clock()</span></tt></a> has microsecond granularity but <a title="time.time" class="reference external" href="time.html#time.time"><tt class="xref docutils literal"><span class="pre">time.time()</span></tt></a>&#8216;s
granularity is 1/60th of a second; on Unix, <a title="time.clock" class="reference external" href="time.html#time.clock"><tt class="xref docutils literal"><span class="pre">time.clock()</span></tt></a> has 1/100th of a
second granularity and <a title="time.time" class="reference external" href="time.html#time.time"><tt class="xref docutils literal"><span class="pre">time.time()</span></tt></a> is much more precise.  On either
platform, the default timer functions measure wall clock time, not the CPU time.
This means that other processes running on the same computer may interfere with
the timing.  The best thing to do when accurate timing is necessary is to repeat
the timing a few times and use the best time.  The <em class="xref">-r</em> option is good
for this; the default of 3 repetitions is probably enough in most cases.  On
Unix, you can use <a title="time.clock" class="reference external" href="time.html#time.clock"><tt class="xref docutils literal"><span class="pre">time.clock()</span></tt></a> to measure CPU time.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">There is a certain baseline overhead associated with executing a pass statement.
The code here doesn&#8217;t try to hide it, but you should be aware of it.  The
baseline overhead can be measured by invoking the program without arguments.</p>
</div>
<p>The baseline overhead differs between Python versions!  Also, to fairly compare
older Python versions to Python 2.3, you may want to use Python&#8217;s <a class="reference external" href="../using/cmdline.html#cmdoption-O"><em class="xref">-O</em></a>
option for the older versions to avoid timing <tt class="docutils literal"><span class="pre">SET_LINENO</span></tt> instructions.</p>
</div>
<div class="section" id="examples">
<h2>27.6.2. Examples<a class="headerlink" href="#examples" title="Permalink to this headline">¶</a></h2>
<p>Here are two example sessions (one using the command line, one using the module
interface) that compare the cost of using <a title="hasattr" class="reference external" href="functions.html#hasattr"><tt class="xref docutils literal"><span class="pre">hasattr()</span></tt></a> vs.
<a class="reference external" href="../reference/compound_stmts.html#try"><tt class="xref docutils literal"><span class="pre">try</span></tt></a>/<a class="reference external" href="../reference/compound_stmts.html#except"><tt class="xref docutils literal"><span class="pre">except</span></tt></a> to test for missing and present object
attributes.</p>
<div class="highlight-python"><pre>% timeit.py 'try:' '  str.__nonzero__' 'except AttributeError:' '  pass'
100000 loops, best of 3: 15.7 usec per loop
% timeit.py 'if hasattr(str, "__nonzero__"): pass'
100000 loops, best of 3: 4.26 usec per loop
% timeit.py 'try:' '  int.__nonzero__' 'except AttributeError:' '  pass'
1000000 loops, best of 3: 1.43 usec per loop
% timeit.py 'if hasattr(int, "__nonzero__"): pass'
100000 loops, best of 3: 2.23 usec per loop</pre>
</div>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">timeit</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">s</span> <span class="o">=</span> <span class="s">&quot;&quot;&quot;</span><span class="se">\</span>
<span class="gp">... </span><span class="s">try:</span>
<span class="gp">... </span><span class="s">    str.__nonzero__</span>
<span class="gp">... </span><span class="s">except AttributeError:</span>
<span class="gp">... </span><span class="s">    pass</span>
<span class="gp">... </span><span class="s">&quot;&quot;&quot;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">t</span> <span class="o">=</span> <span class="n">timeit</span><span class="o">.</span><span class="n">Timer</span><span class="p">(</span><span class="n">stmt</span><span class="o">=</span><span class="n">s</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">print</span> <span class="s">&quot;</span><span class="si">%.2f</span><span class="s"> usec/pass&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="mf">1000000</span> <span class="o">*</span> <span class="n">t</span><span class="o">.</span><span class="n">timeit</span><span class="p">(</span><span class="n">number</span><span class="o">=</span><span class="mf">100000</span><span class="p">)</span><span class="o">/</span><span class="mf">100000</span><span class="p">)</span>
<span class="go">17.09 usec/pass</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">s</span> <span class="o">=</span> <span class="s">&quot;&quot;&quot;</span><span class="se">\</span>
<span class="gp">... </span><span class="s">if hasattr(str, &#39;__nonzero__&#39;): pass</span>
<span class="gp">... </span><span class="s">&quot;&quot;&quot;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">t</span> <span class="o">=</span> <span class="n">timeit</span><span class="o">.</span><span class="n">Timer</span><span class="p">(</span><span class="n">stmt</span><span class="o">=</span><span class="n">s</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">print</span> <span class="s">&quot;</span><span class="si">%.2f</span><span class="s"> usec/pass&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="mf">1000000</span> <span class="o">*</span> <span class="n">t</span><span class="o">.</span><span class="n">timeit</span><span class="p">(</span><span class="n">number</span><span class="o">=</span><span class="mf">100000</span><span class="p">)</span><span class="o">/</span><span class="mf">100000</span><span class="p">)</span>
<span class="go">4.85 usec/pass</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">s</span> <span class="o">=</span> <span class="s">&quot;&quot;&quot;</span><span class="se">\</span>
<span class="gp">... </span><span class="s">try:</span>
<span class="gp">... </span><span class="s">    int.__nonzero__</span>
<span class="gp">... </span><span class="s">except AttributeError:</span>
<span class="gp">... </span><span class="s">    pass</span>
<span class="gp">... </span><span class="s">&quot;&quot;&quot;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">t</span> <span class="o">=</span> <span class="n">timeit</span><span class="o">.</span><span class="n">Timer</span><span class="p">(</span><span class="n">stmt</span><span class="o">=</span><span class="n">s</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">print</span> <span class="s">&quot;</span><span class="si">%.2f</span><span class="s"> usec/pass&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="mf">1000000</span> <span class="o">*</span> <span class="n">t</span><span class="o">.</span><span class="n">timeit</span><span class="p">(</span><span class="n">number</span><span class="o">=</span><span class="mf">100000</span><span class="p">)</span><span class="o">/</span><span class="mf">100000</span><span class="p">)</span>
<span class="go">1.97 usec/pass</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">s</span> <span class="o">=</span> <span class="s">&quot;&quot;&quot;</span><span class="se">\</span>
<span class="gp">... </span><span class="s">if hasattr(int, &#39;__nonzero__&#39;): pass</span>
<span class="gp">... </span><span class="s">&quot;&quot;&quot;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">t</span> <span class="o">=</span> <span class="n">timeit</span><span class="o">.</span><span class="n">Timer</span><span class="p">(</span><span class="n">stmt</span><span class="o">=</span><span class="n">s</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">print</span> <span class="s">&quot;</span><span class="si">%.2f</span><span class="s"> usec/pass&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="mf">1000000</span> <span class="o">*</span> <span class="n">t</span><span class="o">.</span><span class="n">timeit</span><span class="p">(</span><span class="n">number</span><span class="o">=</span><span class="mf">100000</span><span class="p">)</span><span class="o">/</span><span class="mf">100000</span><span class="p">)</span>
<span class="go">3.15 usec/pass</span>
</pre></div>
</div>
<p>To give the <tt class="xref docutils literal"><span class="pre">timeit</span></tt> module access to functions you define, you can pass a
<tt class="docutils literal"><span class="pre">setup</span></tt> parameter which contains an import statement:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">test</span><span class="p">():</span>
    <span class="s">&quot;Stupid test function&quot;</span>
    <span class="n">L</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mf">100</span><span class="p">):</span>
        <span class="n">L</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>

<span class="k">if</span> <span class="n">__name__</span><span class="o">==</span><span class="s">&#39;__main__&#39;</span><span class="p">:</span>
    <span class="kn">from</span> <span class="nn">timeit</span> <span class="kn">import</span> <span class="n">Timer</span>
    <span class="n">t</span> <span class="o">=</span> <span class="n">Timer</span><span class="p">(</span><span class="s">&quot;test()&quot;</span><span class="p">,</span> <span class="s">&quot;from __main__ import test&quot;</span><span class="p">)</span>
    <span class="k">print</span> <span class="n">t</span><span class="o">.</span><span class="n">timeit</span><span class="p">()</span>
</pre></div>
</div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <h3><a href="../contents.html">Table Of Contents</a></h3>
            <ul>
<li><a class="reference external" href="">27.6. <tt class="docutils literal"><span class="pre">timeit</span></tt> &#8212; Measure execution time of small code snippets</a><ul>
<li><a class="reference external" href="#command-line-interface">27.6.1. Command Line Interface</a></li>
<li><a class="reference external" href="#examples">27.6.2. Examples</a></li>
</ul>
</li>
</ul>

            <h4>Previous topic</h4>
            <p class="topless"><a href="hotshot.html"
                                  title="previous chapter">27.5. <tt class="docutils literal docutils literal docutils literal"><span class="pre">hotshot</span></tt> &#8212; High performance logging profiler</a></p>
            <h4>Next topic</h4>
            <p class="topless"><a href="trace.html"
                                  title="next chapter">27.7. <tt class="docutils literal docutils literal"><span class="pre">trace</span></tt> &#8212; Trace or track Python statement execution</a></p>
            <h3>This Page</h3>
            <ul class="this-page-menu">
              <li><a href="../_sources/library/timeit.txt"
                     rel="nofollow">Show Source</a></li>
            </ul>
          <div id="searchbox" style="display: none">
            <h3>Quick search</h3>
              <form class="search" action="../search.html" method="get">
                <input type="text" name="q" size="18" />
                <input type="submit" value="Go" />
                <input type="hidden" name="check_keywords" value="yes" />
                <input type="hidden" name="area" value="default" />
              </form>
              <p class="searchtip" style="font-size: 90%">
              Enter search terms or a module, class or function name.
              </p>
          </div>
          <script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../modindex.html" title="Global Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="trace.html" title="27.7. trace — Trace or track Python statement execution"
             >next</a> |</li>
        <li class="right" >
          <a href="hotshot.html" title="27.5. hotshot — High performance logging profiler"
             >previous</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="../index.html">Python v2.6.2 documentation</a> &raquo;</li>

          <li><a href="index.html" >The Python Standard Library</a> &raquo;</li>
          <li><a href="debug.html" >27. Debugging and Profiling</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
      &copy; <a href="../copyright.html">Copyright</a> 1990-2009, Python Software Foundation.
      Last updated on Apr 15, 2009.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6.1.
    </div>
  </body>
</html>